package cn.yunyichina.provider.drug.service.impl;

import cn.yunyichina.provider.drug.dao.CatalogueDao;
import cn.yunyichina.provider.drug.entity.Catalogue;
import cn.yunyichina.provider.drug.vo.CatalogueChangeLog;
import cn.yunyichina.provider.drug.vo.CatalogueRequestVo;
import cn.yunyichina.provider.framework.common.PKGenerator;
import cn.yunyichina.provider.framework.dubbo.service.BaseService;
import cn.yunyichina.provider.framework.dubbo.service.CacheService;
import cn.yunyichina.provider.framework.page.PageInfo;
import cn.yunyichina.provider.iface.entity.base.LogVo;
import cn.yunyichina.provider.iface.entity.cache.SessionInfo;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.utils.commons.DateUtils;
import cn.yunyichina.utils.convert.JsonUtils;
import com.alibaba.dubbo.common.utils.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2017/7/21.
 */
@Service
public class CatalogueServiceImpl {

    private Logger logger = LoggerFactory.getLogger(CatalogueServiceImpl.class);
    private static SimpleDateFormat YYYYMMDDHHMMSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private CatalogueDao dao;

    /**
     * 药品目录上传
     * yyt.drug.catalogue.excel.import
     * @param data
     * @param sessionId
     * @return
     */
    public Response importCatalogueExcel(String data, String sessionId) {
        logger.info("【drug模块-药品目录上传】开始, 请求="+data,",sessionId=" + sessionId);
        Response response = new Response();

        Map<String,String> vo = JsonUtils.parseObject(data,Map.class);
        String remoteFile = vo.get("url");
        logger.info("【drug模块-药品目录上传】导入excel:url =" + remoteFile);
        Map<String,Object> map = readExcelFile(remoteFile);
        if(map.containsKey("error")){
            response.setResultCodeAndMessage("90002", (String) map.get("error"));
            return response;
        }

        List<Catalogue> catalogueList = new ArrayList<>();
        if(map != null && map.size()>0){
            String createTime =  DateUtils.dateToString(new Date());
            for(Map.Entry<String,Object> entry:map.entrySet()){
                if(entry.getValue() instanceof Catalogue) {
                    Catalogue catalogue = (Catalogue) entry.getValue();
                    catalogue.setCreatedTime(createTime);
                    catalogueList.add(catalogue);
                }
            }
        }
        if(catalogueList.size() > 0) {
            dao.batchInsert(catalogueList);
            List<Map<String, Object>> ids = dao.getDuplicateIds();
            List<String> idList = new ArrayList<>();
            for (Map<String, Object> id : ids) {
                idList.add(id.get("ID").toString());
            }
            if(idList != null && idList.size() > 0){
                dao.deleteByIds(idList);
            }
        }
        logger.info("【drug模块-药品目录上传】导入excel:成功导入" + catalogueList.size() +"条数据");
        response.setResultCodeAndMessage("0","成功导入" + catalogueList.size() +"条数据。" + map.get("tips"));
        return response;
    }


    /**
     * 读取单元格的数据
     * @param remoteFilePath
     * @return
     */
    public  Map<String,Object> readExcelFile(String remoteFilePath){
        InputStream is = null;
        Workbook wb = null;
        HashMap<String, Object> map = new HashMap();
        String tips = "";
        try {
            URL urlfile = new URL(remoteFilePath);
            HttpURLConnection httpUrl = (HttpURLConnection)urlfile.openConnection();

            URL url = new URL(remoteFilePath);
            URLConnection conn = url.openConnection();
            conn.setConnectTimeout(3000);
            conn.setReadTimeout(3 * 60 * 1000);
            is = conn.getInputStream();
            wb = WorkbookFactory.create(is);
            Sheet sheet = wb.getSheetAt(0);

            int row_num=sheet.getLastRowNum();
            for(int i=1 ;i<= row_num ;i++){
                Row row=sheet.getRow(i);

                String hospitalCode = readValue(row.getCell(0));
                String hospitalName = readValue(row.getCell(1));
                String goodsId = readValue(row.getCell(2));
                String orgId = readValue(row.getCell(3));
                String orgCode = readValue(row.getCell(4));
                String orgName = readValue(row.getCell(5));
                String drugId = readValue(row.getCell(6));
                String goodsName = readValue(row.getCell(7));
                String drugName = readValue(row.getCell(8));
                String goodsSpec = readValue(row.getCell(9));
                String drugSpec = readValue(row.getCell(10));
                String drugUnitNum = readValue(row.getCell(11));
                String drugUnitLimit = readValue(row.getCell(12));
                String drugUnitMax = readValue(row.getCell(13));
                String goodsSocialInsuranceId = readValue(row.getCell(14));
                String drugSocialInsuranceId = readValue(row.getCell(15));
                String goodsApprovalNo = readValue(row.getCell(16));
                String drugApprovalNo = readValue(row.getCell(17));
                String drugPrice = readValue(row.getCell(18));
                String goodsPrice = readValue(row.getCell(19));
                String isCell = readValue(row.getCell(20));

                if(StringUtils.isBlank(hospitalCode)){
                    logger.info("第" + i +"行<医院编码>不能为空");
                    tips += "第" + i +"行<医院编码>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(hospitalName)){
                    logger.info("第" + i +"行<医院名称>不能为空");
                    tips += "第" + i +"行<医院名称>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(goodsId)){
                    logger.info("第" + i +"行<医院药品编码>不能为空");
                    tips += "第" + i +"行<医院药品编码>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(orgId)){
                    logger.info("第" + i +"行<药店机构ID>不能为空");
                    tips += "第" + i +"行<药店机构ID>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(orgCode)){
                    logger.info("第" + i +"行<药店机构编码>不能为空");
                    tips += "第" + i +"行<药店机构编码>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(drugId)){
                    logger.info("第" + i +"行<药店药品编码>不能为空");
                    tips += "第" + i +"行<药店药品编码>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(drugUnitNum)){
                    logger.info("第" + i +"行<包装数量>不能为空");
                    tips += "第" + i +"行<包装数量>不能为空;";
                    continue;
                }
                if(StringUtils.isBlank(drugPrice)){
                    logger.info("第" + i +"行<药店药品单价>不能为空");
                    tips += "第" + i +"行<药店药品单价>不能为空;";
                    continue;
                }

                String key = hospitalCode + goodsId + orgCode + drugId;
                if(map.containsKey(key)){
                    logger.info("导入的模板中有重复的<医院编码+医院药品编码+药店机构编码+药店药品编码>数据，请检查:医院编码=" + hospitalCode + ",医院药品编码=" + goodsId + ",药店机构编码=" + orgCode + ",药店药品编码=" + drugId);
                    tips += "导入的模板中有重复的<医院编码+医院药品编码+药店机构编码+药店药品编码>数据，请检查:医院编码=" + hospitalCode + ",医院药品编码=" + goodsId + ",药店机构编码=" + orgCode + ",药店药品编码=" + drugId;
                    continue;
                }

                Catalogue catalogue = new Catalogue();
                catalogue.setId(PKGenerator.generateId());
                catalogue.setHospitalCode(hospitalCode);
                catalogue.setHospitalName(hospitalName);
                catalogue.setGoodsId(goodsId);
                catalogue.setGoodsName(goodsName);
                catalogue.setGoodsSocialInsuranceId(goodsSocialInsuranceId);
                catalogue.setGoodsApprovalNo(goodsApprovalNo);
                catalogue.setGoodsSpec(goodsSpec);
                catalogue.setOrgId(orgId);
                catalogue.setOrgCode(orgCode);
                catalogue.setOrgName(orgName);
                catalogue.setDrugId(drugId);
                catalogue.setDrugName(drugName);
                catalogue.setDrugSocialInsuranceId(drugSocialInsuranceId);
                catalogue.setDrugApprovalNo(drugApprovalNo);
                catalogue.setDrugSpec(drugSpec);
                catalogue.setDrugUnitNum(Integer.parseInt(drugUnitNum.trim()));
                catalogue.setDrugUnitLimit(drugUnitLimit);
                catalogue.setDrugUnitMax(drugUnitMax);
//                catalogue.setDrugPrice(Integer.parseInt(new DecimalFormat("0").format(Double.parseDouble(drugPrice) * 100)));
                catalogue.setDrugPrice(Double.parseDouble(drugPrice));
                catalogue.setGoodsPrice(Integer.parseInt(goodsPrice));
                if(StringUtils.isNotBlank(isCell)){
                    catalogue.setIsCell(Integer.parseInt(isCell));
                }

                map.put(key,catalogue);
            }
            map.put("tips",tips);
            return map;

        } catch (Exception e) {
            e.printStackTrace();
            map.put("error","导入发生异常，请检查导入文件的格式");

        }finally{

        }
        return map;
    }



    public static String readValue(Cell cell) {
        String value = "";
        if (cell == null) {
            return "";
        }

        int rowType = cell.getCellType();
        if (rowType == Cell.CELL_TYPE_STRING) {
            value = cell.getStringCellValue();

        } else if (rowType == Cell.CELL_TYPE_NUMERIC) {
            if (HSSFDateUtil.isCellDateFormatted(cell)) {

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String date = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString();
                value = date.toString();

            } else {
                DecimalFormat df = new DecimalFormat("0");
                value = df.format(cell.getNumericCellValue());
            }

        }


        return value;
    }

    /**
     * 获取合并单元格的值
     * @param sheet
     * @param row
     * @param column
     * @return
     */
    public static String getMergedRegionValue(Sheet sheet ,int row , int column){
        int sheetMergeCount = sheet.getNumMergedRegions();

        for(int i = 0 ; i < sheetMergeCount ; i++){
            CellRangeAddress ca = sheet.getMergedRegion(i);
            int firstColumn = ca.getFirstColumn();
            int lastColumn = ca.getLastColumn();
            int firstRow = ca.getFirstRow();
            int lastRow = ca.getLastRow();

            if(row >= firstRow && row <= lastRow){

                if(column >= firstColumn && column <= lastColumn){
                    Row fRow = sheet.getRow(firstRow);
                    Cell fCell = fRow.getCell(firstColumn);

                    return getCellValue(fCell) ;
                }
            }
        }

        return null ;
    }

    /**
     * 获取单元格的值
     * @param cell
     * @return
     */
    public static String getCellValue(Cell cell){

        if(cell == null) return "";

        if(cell.getCellType() == Cell.CELL_TYPE_STRING){

            return cell.getStringCellValue();

        }else if(cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){

            return String.valueOf(cell.getBooleanCellValue());

        }else if(cell.getCellType() == Cell.CELL_TYPE_FORMULA){

            return cell.getCellFormula() ;

        }else if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){

            return String.valueOf(cell.getNumericCellValue());

        }

        return "";
    }

    /**yyt.drug.catalogue.list
     * 药品目录列表查询
     * @param data
     * @param sessionId
     * @return
     */
    public Response listCatalogue(String data, String sessionId) {
        logger.info("【drug模块-药品目录列表查询原始入参】, 请求="+data,",sessionId=" + sessionId);
        Response response = new Response();
        try{
            Catalogue requestVo = JsonUtils.parseObject(data,Catalogue.class);
            PageInfo pageInfo = JsonUtils.parseObject(data,PageInfo.class);
            if (pageInfo !=null){
                //支持分页
                if(pageInfo.getPageNum()== null ||pageInfo.getPageSize()== null){
                    response.setResultCodeAndMessage("23001", "page_num或page_size不能为空");
                    logger.info("【drug模块-药品目录列表查询出参】,response={}",JsonUtils.toJsonString(response));
                    return response;
                }

                if (StringUtils.isNotBlank(requestVo.getBeginCreatedTime()) && StringUtils.isNotBlank(requestVo.getEndCreatedTime())){
                    if (requestVo.getBeginCreatedTime().compareTo(requestVo.getEndCreatedTime())>0){
                        response.setResultCodeAndMessage("23001","开始时间不能大于结束时间");
                        logger.info("【drug模块-药品目录列表查询出参】,response={}",JsonUtils.toJsonString(response));
                        return response;
                    }
                    String beginCreatedTime = requestVo.getBeginCreatedTime()+" 00:00:00";
                    String endCreatedTime = requestVo.getEndCreatedTime() + " 23:59:59";
                    requestVo.setBeginCreatedTime(beginCreatedTime);
                    requestVo.setEndCreatedTime(endCreatedTime);
                }

                List<String> orderColumns = new ArrayList<>();
                orderColumns.add("update_time");
                Map<String,Object> resultMap = new HashMap<>();
                List<Catalogue> catalogueList = dao.select(requestVo,orderColumns,false,pageInfo);
                Long dataCount = dao.selectCount(requestVo);
                pageInfo.setTotal(dataCount);
                pageInfo.setPages((pageInfo.getTotal().intValue() + pageInfo.getPageSize() - 1) / pageInfo.getPageSize());
                resultMap.put("page_info",pageInfo);
                resultMap.put("list",catalogueList);
                response.setResultCodeAndMessageAndResult("0","成功",JsonUtils.toJsonString(resultMap));
            }else {
                List<Catalogue> catalogueList = dao.select(requestVo);
                response.setResultCodeAndMessageAndResult("0","成功",JsonUtils.toJsonString(catalogueList));
            }
        }catch (Exception e){
            logger.error("【drug模块-药品目录列表查询异常】,errMsg={}",e.getMessage());
            response.setResultCodeAndMessage("23999","异常:" + e.getMessage());
        }
        logger.info("【drug模块-药品目录列表查询出参】,response={}",JsonUtils.toJsonString(response));
        return response;
    }

    /**yyt.drug.catalogue.add
     * 新增药品
     * @param data
     * @param sessionId
     * @return
     */
    public Response addCatalogue(String data, String sessionId) {
        logger.info("【drug模块-新增药品原始入参】, 请求="+data,",sessionId=" + sessionId);
        Response response = new Response();
        try {
            Catalogue catalogue = JsonUtils.parseObject(data,Catalogue.class);
            if(StringUtils.isBlank(catalogue.getDrugId()) ||StringUtils.isBlank(catalogue.getDrugName())||catalogue.getDrugUnitNum()==null||catalogue.getDrugUnitLimit()==null
                    ||catalogue.getDrugUnitMax() ==null ||catalogue.getDrugPrice()==null){
                response.setResultCodeAndMessage("23001","药店药品参数缺失");
                return response;
            }

            if(StringUtils.isBlank(catalogue.getHospitalCode()) ||StringUtils.isBlank(catalogue.getHospitalName())||StringUtils.isBlank(catalogue.getGoodsId())){
                response.setResultCodeAndMessage("23001","医院药品参数缺失");
                return response;
            }

            catalogue.setId(PKGenerator.generateId());
            catalogue.setCreatedTime(DateUtils.dateToString(new Date()));
            catalogue.setUpdateTime(DateUtils.dateToString(new Date()));
            dao.insert(catalogue);

            response.setResultCodeAndMessage("0","新增药品成功");
        }catch (Exception e){
            logger.error("【drug模块-新增药品异常】,errMsg={}",e.getMessage());
            response.setResultCodeAndMessage("23999","异常:" + e.getMessage());
        }
        return response;
    }

    /**yyt.drug.catalogue.update
     * 更新药品
     * @param data
     * @param sessionId
     * @return
     */
    public Response updateCatalogue(String data, String sessionId) {
        logger.info("【drug模块-更新药品原始入参】, 请求="+data,",sessionId=" + sessionId);
        Response response = new Response();
        try {
            CatalogueRequestVo requestVo = JsonUtils.parseObject(data,CatalogueRequestVo.class);
            if (StringUtils.isBlank(requestVo.getId())){
                response.setResultCodeAndMessage("23001","参数缺失请检查");
            }

            Catalogue dbCatalogue = dao.selectById(requestVo.getId());
            if (dbCatalogue !=null){
                SessionInfo sessionInfo = CacheService.getSessionInfo(sessionId);
                Catalogue updateCatalogue = new Catalogue();
                updateCatalogue.setId(requestVo.getId());
                updateCatalogue.setDrugId(requestVo.getDrugId());
                updateCatalogue.setDrugName(requestVo.getDrugName());
                updateCatalogue.setUpdateTime(DateUtils.dateToString(new Date()));
                updateCatalogue.setUpdateBy(sessionInfo ==null?null:sessionInfo.getLoginName());
                updateCatalogue.setDrugUnitMax(requestVo.getDrugUnitMax());
                updateCatalogue.setDrugUnitLimit(requestVo.getDrugUnitLimit());
                updateCatalogue.setDrugUnitNum(requestVo.getDrugUnitNum());
                updateCatalogue.setDrugPrice(requestVo.getDrugPrice());
                updateCatalogue.setDrugApprovalNo(requestVo.getDrugApprovalNo());
                updateCatalogue.setDrugSpec(requestVo.getDrugSpec());
                if(requestVo.getEnableFlag() != null){
                    updateCatalogue.setEnableFlag(requestVo.getEnableFlag());
                }

               List<CatalogueChangeLog> changeLogList = new ArrayList<>();
                /**修改的记录日志拼接*/
                if (!StringUtils.equals(dbCatalogue.getDrugId(),updateCatalogue.getDrugId())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugId());
                    changeLog.setNewValue(updateCatalogue.getDrugId());
                    changeLog.setTitle("药店药品编码");
                    changeLogList.add(changeLog);
                }
                if (!StringUtils.equals(dbCatalogue.getDrugName(),updateCatalogue.getDrugName())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugName());
                    changeLog.setNewValue(updateCatalogue.getDrugName());
                    changeLog.setTitle("药店药品名称");
                    changeLogList.add(changeLog);
                }
                if (!dbCatalogue.getDrugPrice().equals(updateCatalogue.getDrugPrice())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugPrice() !=null ? String.valueOf(dbCatalogue.getDrugPrice()/100f):null);
                    changeLog.setNewValue(updateCatalogue.getDrugPrice()!=null?String.valueOf(updateCatalogue.getDrugPrice()/100f):null);
                    changeLog.setTitle("药店药品价格");
                    changeLogList.add(changeLog);
                }
                if (!StringUtils.equals(dbCatalogue.getDrugApprovalNo(),updateCatalogue.getDrugApprovalNo())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugApprovalNo());
                    changeLog.setNewValue(updateCatalogue.getDrugApprovalNo());
                    changeLog.setTitle("药店药品批准文号");
                    changeLogList.add(changeLog);

                }
                if (!dbCatalogue.getDrugUnitNum().equals(updateCatalogue.getDrugUnitNum())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(String.valueOf(dbCatalogue.getDrugUnitNum()));
                    changeLog.setNewValue(String.valueOf(updateCatalogue.getDrugUnitNum()));
                    changeLog.setTitle("药店药品包装数量");
                    changeLogList.add(changeLog);
                }
                if (!StringUtils.equals(dbCatalogue.getDrugUnitLimit(),updateCatalogue.getDrugUnitLimit())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugUnitLimit());
                    changeLog.setNewValue(updateCatalogue.getDrugUnitLimit());
                    changeLog.setTitle("药店药品小包装单位");
                    changeLogList.add(changeLog);
                }
                if (!StringUtils.equals(dbCatalogue.getDrugUnitMax(),updateCatalogue.getDrugUnitMax())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugUnitMax());
                    changeLog.setNewValue(updateCatalogue.getDrugUnitMax());
                    changeLog.setTitle("药店药品大包装单位");
                    changeLogList.add(changeLog);
                }
                if (!StringUtils.equals(dbCatalogue.getDrugSpec(),updateCatalogue.getDrugSpec())){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getDrugSpec());
                    changeLog.setNewValue(updateCatalogue.getDrugSpec());
                    changeLog.setTitle("药店药品规格");
                    changeLogList.add(changeLog);
                }
                if (dbCatalogue.getEnableFlag() != updateCatalogue.getEnableFlag()){
                    CatalogueChangeLog changeLog = new CatalogueChangeLog();
                    changeLog.setChangeDate(DateUtils.dateToString(new Date()));
                    changeLog.setOldValue(dbCatalogue.getEnableFlag() !=null?Short.toString(dbCatalogue.getEnableFlag()):null);
                    changeLog.setNewValue(updateCatalogue.getEnableFlag() !=null ?Short.toString(updateCatalogue.getEnableFlag()):null);
                    if("0".equals(changeLog.getOldValue())){
                        changeLog.setOldValue("下架");
                    }else{
                        changeLog.setOldValue("上架");
                    }
                    if("0".equals(changeLog.getNewValue())){
                        changeLog.setNewValue("下架");
                    }else{
                        changeLog.setNewValue("上架");
                    }
                    changeLog.setTitle("药店药品上下架");
                    changeLogList.add(changeLog);
                }

                if (CollectionUtils.isNotEmpty(changeLogList)){
                    //构建日志记录对象
                    LogVo logVo = new LogVo();
                    logVo.setId(PKGenerator.generateId());
                    logVo.setBatchNo(dbCatalogue.getId());
                    logVo.setContent(JsonUtils.toJsonString(changeLogList));
                    logVo.setOperatorTime(DateUtils.dateToString(new Date()));
                    logVo.setOperatorBy(sessionInfo.getLoginName());
                    logVo.setOperatorName(sessionInfo.getUserName());
                    logVo.setOrgId(dbCatalogue.getOrgId());
                    logVo.setOrgCode(dbCatalogue.getOrgCode());
                    logVo.setOrgName(dbCatalogue.getOrgName());
                    dao.update(updateCatalogue);
                    insertLog(logVo);
                }
                response.setResultCodeAndMessage("0","更新药品成功");
            }

        }catch (Exception e){
            logger.error("【drug模块-更新药品异常】,errMsg={}",e);
            response.setResultCodeAndMessage("23999","异常:" + e.getMessage());
        }
        return response;
    }

    public void insertLog(LogVo log) {
        try {
            if (StringUtils.isBlank(log.getId())) {
                log.setId(PKGenerator.generateId());
            }
            if (StringUtils.isBlank(log.getEventCode())) {
                log.setEventCode("PBM");
            }
            if (StringUtils.isBlank(log.getModuleCode())) {
                log.setModuleCode("PBM");
            }

            if (log.getLevel() == null) {
                log.setLevel((short) 1 );
             }
            if (StringUtils.isBlank(log.getModuleName())) {
                log.setModuleName("PBM系统");
            }
            BaseService.callHumpFromInternal("yyt.base.log.insert", JsonUtils.toJsonString(log));
        } catch (Exception e) {
            logger.error("记录PMB日志系统异常 errMsg={}",e.getMessage());
        }
    }

}
